(() => {
	let page = 1;
	let ele = {};
	ele.list = $('#list');
	ele.more = $('#more');
	ele.empty = $('#empty');

	ele.active = $('#active');

	getUserInfo(res => {
		ele.active.innerHTML = res.current_family_active
	})


	getDetail(page);

	function getDetail(page) {
		ele.more.innerText = '加载中...';
		let token = getCookie("token");
		let userid = getCookie("userid");
		ajax({
			url: API_PATH.ACTIVERECORD,
			method: 'GET',
			header: {
				Authorization: token
			},
			data: {
				page: page
			},
			success: res => {
				if (res.code == 1) {
					let detail = res.data.data;
					if (detail.length === 0) {
						page = 0;
						ele.more.style.display = "none";
						ele.empty.style.display = "block";
					} else {
						drawDetail(detail);
						page++;
						if (page > res.data.last_page) {
							ele.more.innerText = '没有更多了';
							ele.more.onclick = null;
						}
						else {
							ele.more.innerText = '加载更多';
							ele.more.onclick = () => getDetail(page);
						}
					}
				}
				else openTips(res.msg);
			}
		});
	}

	function drawDetail(data) {
		if (data.length === 0) {
			page = 0;
			ele.more.style.display = "none";
			ele.empty.style.display = "block";
		} else {
			let str = '';
			for (let i = 0; i < data.length; i++) {
				let sign = data[i].type_text
				str += '<div class="item">' +
					'<div class="item-box">' +
					'<div class="left">' +
					'<p class="resume">' + data[i].format_text + '</p>' +
					'<p class="time">' + data[i].created_at + '</p>' +
					'</div>' +
					'</div>' +
					'<p class="amount">' + sign + data[i].active + '</p>' +
					'</div>';
			}
			ele.list.innerHTML += str;
		}
	}
})();
